package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import me.zhengjie.modules.system.domain.Dept
import me.zhengjie.modules.system.domain.Menu

import io.swagger.v3.oas.annotations.media.Schema
import org.apache.commons.lang3.builder.ToStringBuilder


import java.io.Serializable
import java.sql.Timestamp
/**
 * @author Kuki Wu
 * @date 2024-11-23
 */
@Schema(description = "规则dto类")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
@JsonTypeName("RoleDTO")
data class RoleDTO (

    @Schema(description = "id", required = true, hidden = true)
    var id: Long? = null,

    @Schema(description = "规则名称", required = false)
    var name: String? = null,

    @Schema(description = "数据范围", required = false)
    var dataScope: String? = null,

    @Schema(description = "等级", required = false)
    var level: Int? = null,

    @Schema(description = "备注", required = false)
    var remark: String? = null,

    @Schema(description = "权限", required = false)
    var permission: String? = null,

    @Schema(description = "菜单", required = false)
    @get:JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
    @get:JsonInclude(JsonInclude.Include.NON_EMPTY)
    var menus: MutableSet<Menu>? = mutableSetOf(),

    @Schema(description = "部门", required = false)
    @get:JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
    @get:JsonInclude(JsonInclude.Include.NON_EMPTY)
    var depts: MutableSet<Dept>? = mutableSetOf(),

    @Schema(description = "创建时间", required = false)
    var createTime: Timestamp? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): RoleDTO? {
            val obj=JacksonUtil.parseObject(json, RoleDTO::class.java)!!
            return when(obj){
                is RoleDTO -> obj
                else -> null
            }
        }
    }
    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: RoleDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}